package com.StarStudio.DAO;


import com.ruoyi.common.core.Entity.PanicBuyingGoods;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PanicBuyingGoodsDAO {

    List<PanicBuyingGoods> findPanicBuyingGoodsList(PanicBuyingGoods panicBuyingGoods);

    @Select("select count(panic_buying_goods_id) from panic_buying_goods where del_flag = false")
    long findTotalRecord();

    @Select("select * from panic_buying_goods where goods_id = #{goods_id} and del_flag = false limit 1")
    PanicBuyingGoods findByGoods_id(long goods_id);

    int updatePanicBuyingGoods(PanicBuyingGoods panicBuyingGoods);

    @Select("select * from panic_buying_goods where del_flag = false")
    List<PanicBuyingGoods> PanicBuyingGoodsList();

    @Select("select * from panic_buying_goods where panic_buying_status = #{status} and del_flag = false")
    List<PanicBuyingGoods> findByStatus(int status);

    @Insert("insert into panic_buying_goods values (#{panic_buying_goods_id},#{goods_id},#{panic_buying_price},#{panic_buying_goods_stock},#{panic_buying_start_time}," +
            "#{panic_buying_end_time},#{panic_buying_status},#{del_flag})")
    void AddPanicBuyingGoods(PanicBuyingGoods panicBuyingGoods);

    @Update("update panic_buying_goods set del_flag = true,panic_buying_goods_stock = 0 where panic_buying_goods_id = #{panic_buying_goods_id}")
    void DeletePanicBuyingGoods(long panic_buying_goods_id);

    @Select("select panic_buying_goods_stock from panic_buying_goods where panic_buying_goods_id = #{Panic_buying_goods_id}")
    int findByPanic_buying_goods_stockByPanic_buying_goods_id(long Panic_buying_goods_id);

    @Select("select goods_id from panic_buying_goods where panic_buying_goods_id = #{panic_buying_goods_id}")
    long findGoodsIdByPBGId(long panic_buying_goods_id);

    @Select("select panic_buying_goods_stock from panic_buying_goods where goods_id = #{goods_id} and del_flag = false")
    int findPBGoodsStockByGoodsId(long goods_id);

    List<Long> getGoodsIdListFromPanicBuyingGoods();

    @Update("update panic_buying_goods set panic_buying_goods_stock = panic_buying_goods_stock - 1 where goods_id = #{goods_id} and panic_buying_goods_stock > 0")
    int reduceStock(PanicBuyingGoods panicBuyingGoods);

    @Update("update panic_buying_goods set panic_buying_status = #{panic_buying_status} where panic_buying_goods_id = #{panic_buying_goods_id}")
    void updatePanicBuyingGoodsStatus(@Param("panic_buying_goods_id") long panic_buying_goods_id,@Param("panic_buying_status") int panic_buying_status);

    List<PanicBuyingGoods> findPBGoodsByStatusAndStoreId(@Param("status") int status,@Param("storeId") Long storeId);

    List<PanicBuyingGoods> findPanicBuyingGoodsListByStoreId(@Param("pbg") PanicBuyingGoods pbg,@Param("storeId") Long storeId);

    long findStoreTotalRecord(Long storeId);

    @Select("select * from panic_buying_goods where panic_buying_status = 2 and del_flag = false")
    List<PanicBuyingGoods> PanicBuyingEndStatusGoodsList();

    @Select("select goods_id from panic_buying_goods where panic_buying_goods_id = #{panicBuyingGoodsId}")
    Long findGoodsIdByRecordId(Long panicBuyingGoodsId);
}
